<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue3-escook</title>
  <link rel="stylesheet" href="./lib/style.css">
  <script type="importmap">
    {
      "imports" : {
        "vue": "./lib/vue-3.4.29.js"
      }
    }
  </script>
  <script type="module">
    import { createApp, ref, watch, watchEffect, watchSyncEffect } from 'vue'

    const app = createApp({
      setup() {
        const count = ref(0)
        const addThreeTimes = () => {
          for (let i = 0; i < 3; i++) {
            count.value++
          }
        }

        // watch(count, (newCount) => {
        //   console.log(newCount)
        // }, {
        //   // 同步侦听器
        //   flush: 'sync'
        // })

        // watchEffect(() => {
        //   console.log(count.value)
        // }, {
        //   flush: 'sync'
        // })

        watchSyncEffect(() => {
          console.log(count.value)
        })

        return { count, addThreeTimes }
      }
    })

    app.mount('#app')
  </script>
</head>

<body>
  <div id="app">
    <h1>count 的值是：{{ count }}</h1>
    <button @click="addThreeTimes">点击按钮自增3次</button>
  </div>
</body>

</html>